import requests
from util.getheaders import get_init_headers
import hashlib
import json
from util.time_stamp import get_time_stamp

results = []
results_set = set()

while True:
    url = f'https://api.live.bilibili.com/xlive/web-interface/v1/index/getList?platform=web&web_location=444.7&w_rid=d3078c67ac0e6ed1a4c35410d147226b&wts={get_time_stamp()}'
    res = requests.get(url, headers=get_init_headers())
    go_on = True
    for item in res.json()['data']['room_list'][1]['list']:
        print(item)
        item_hash = hashlib.md5(json.dumps(item).encode()).hexdigest()
        if item_hash not in results_set:
            results_set.add(item_hash)
            results.append(item)
            if len(results) == 100:
                go_on = False
                break
        else:
            print(f"发现重复项0...........")
    if not go_on:
        break

print(f'获取到数据{len(results)} {len(results_set)}')

